import { getBrowserType } from './func';

export function openNav({
  map = 'BAIDU',
  to,
  from,
}) {
  const browser = getBrowserType();
  let params;
  switch (map) {
    case 'BAIDU':
      params = `query=${to.address}`;
      if (to.lat) {
        params = `${params}&location=${to.lat},${to.lng}&coord_type=gcj02`;
      }
      console.log('======', params);
      if (browser.ios) {
        // window.location.href = `baidumap://map/direction?origin=${from.lat},${from.lng}&destination=${to}&coord_type=gcj02&mode=driving&src=webapp.navi.youyuer.youyuer`;
        window.location.href = `baidumap://map/navi?${params}&src=webapp.navi.youyuer.youyuer`;
      } else {
        // window.location.href = `bdapp://map/direction?origin=${from.lat},${from.lng}&destination=${to}&coord_type=gcj02&mode=driving&src=webapp.navi.youyuer.youyuer`;
        window.location.href = `baidumap://map/navi?${params}&src=webapp.navi.youyuer.youyuer`;
      }
      break;
    case 'GAODE':
      // if (browser.ios) {
      //   window.location.href = `iosamap://path?sourceApplication=com.youyuer.refuel&slat=${from.lat}&slon=${from.lng}&dname=${to}&dev=0&t=0`;
      // } else {
      //   window.location.href = `androidamap://path?sourceApplication=com.youyuer.refuel&slat=${from.lat}&slon=${from.lng}&dname=${to}&dev=0&t=0`;
      // }
      params = `http://uri.amap.com/navigation?to=${to.lng || ''},${to.lat || ''},${to.address}&mode=car&callnative=1`;
      if (from) {
        params = `${params}&from=${from.lng},${from.lat},我的位置`;
      }
      window.location.href = params;
      break;
    default:
      break;
  }
}
